package com.example.dl645.service;

import io.netty.channel.Channel;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 集中器连接管理器（维护集中器ID与Channel的映射）
 */
@Component
public class ConcentratorConnectionManager {

    private final Map<String, Channel> channelMap = new ConcurrentHashMap<>();

    // 注册集中器连接
    public void register(String concentratorId, Channel channel) {
        channelMap.put(concentratorId, channel);
    }

    // 移除集中器连接
    public void unregister(String concentratorId) {
        channelMap.remove(concentratorId);
    }

    // 获取集中器Channel
    public Channel getChannel(String concentratorId) {
        return channelMap.get(concentratorId);
    }

    // 获取在线集中器数量
    public int getOnlineCount() {
        return channelMap.size();
    }
}